package com.cfr.utils;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

public class TestAccountUtil {
	private Logger logger = Logger.getLogger(this.getClass());

	private static TestAccountUtil testAccountUtil = null;

	private String configPath;
	
	private Properties pros = new Properties();

	public void init(String path) {
		setConfigPath(path);
		loadProperties(path);
	}

	private TestAccountUtil() {}

	public synchronized static TestAccountUtil getInstance() {
		if (testAccountUtil == null) {
			testAccountUtil = new TestAccountUtil();
		}
		return testAccountUtil;
	}

	public synchronized void loadProperties(String path) {
		InputStream isConfig = null;
		try {
			isConfig = new FileInputStream(path + "/config/testaccount.properties");
			if (isConfig != null) {
				pros.load(isConfig);
			}
		} catch (IOException e) {
			logger.error(e.getMessage(), e);
		} finally {
			try {
				isConfig.close();
			} catch (IOException e) {
				logger.info(e.getMessage(), e);
			}
		}
	}

	public String getConfigPath() {
		return configPath;
	}

	public void setConfigPath(String configPath) {
		this.configPath = configPath;
	}
	
	public String getIsOpenHttpBasicAuth() {
		return pros.getProperty("isOpenHttpBasicAuth");
	}
}
